﻿<cfsilent>
	<cfscript>
		
		stringAdvice = getProperty("serviceFactory").getBean("stringAdvice");
		dateTimeAdvice = getProperty("serviceFactory").getBean("datetimeAdvice");
		
		event.setArg("pageTitle", "学生调查问卷 - 在线调查设置向导 - 问卷预览");
		
		questionId = event.getArg("QSN");
		
		currentTab = event.getArg("TabID", "labSetting");
		
		passArgs = structNew();
		structInsert( passArgs, "QSN", questionId, true );
		
		sql = "	SELECT
					q.qsn_id,q.title,q.describe,q.date_start,q.date_end,
					q.grade_allowed,q.institute_allowed,q.gender_allowed
				FROM
					t_questionnaire q
				WHERE
					q.qsn_id = :questionId ";
		
		queryObj = new Query(datasource = application.dnsSlave);
		queryObj.addParam(name = "questionId", value = questionId, cfsqltype = "cf_sql_char");
		rs_quesEntity = queryObj.execute(sql = sql).getResult();
		
		
		
		sql = "	SELECT
					DISTINCT clz.grade
				FROM
					t_class clz INNER JOIN t_subject sbj ON clz.sbj_id = sbj.sbj_id
				WHERE
					clz.cls_scale > 0
					AND
					clz.grade + sbj.schooling_length > :yearNow 
				ORDER BY
					clz.grade";
		
		queryObj = new Query(datasource = application.dnsSlave);
		queryObj.addParam(name = "yearNow", value = year(now()), cfsqltype = "cf_sql_char");
		rs_grade = queryObj.execute(sql = sql).getResult();
		
		
		
		sql = "	SELECT
					DISTINCT i.institute_id,i.institute_short
				FROM
					t_class clz INNER JOIN t_subject sbj ON clz.sbj_id = sbj.sbj_id INNER JOIN t_institute i ON sbj.institute_id = i.institute_id
				WHERE
					clz.cls_scale > 0
					AND
					clz.grade + sbj.schooling_length > :yearNow 
				ORDER BY
					i.institute_short";
		
		queryObj = new Query(datasource = application.dnsSlave);
		queryObj.addParam(name = "yearNow", value = year(now()), cfsqltype = "cf_sql_char");
		rs_institute = queryObj.execute(sql = sql).getResult();
		
		
		
		sql = "	SELECT
				   r.stu_id
				FROM
					t_respondents r
				WHERE
					r.qsn_id = :questionId 
					AND
					r.state = 'U'
				ORDER BY
					r.stu_id";
		
		queryObj = new Query(datasource = application.dnsSlave);
		queryObj.addParam(name = "questionId", value = questionId, cfsqltype = "cf_sql_char");
		rs_studentIds = queryObj.execute(sql = sql).getResult();
		
		
	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				<a class="uiButton" href="<cfoutput>#buildURL('voteList')#</cfoutput>"><i class="mrs img btnList"></i><span class="uiButtonText">调查问卷库</span></a>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 card"></i>时间和调查范围
				</h2>
			</div>
		</div>
	</div>
</div>

<!--- 加载导航菜单 --->
<!-- stepMenu-->
<cfoutput>#event.getArg("stepMenu")#</cfoutput>
<!--/stepMenu-->

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="findStudent">
			
				<div class="UItab">
					<div class="tabLables">
						<span <cfif currentTab eq "labSetting">class="active"</cfif> id="labSetting" tabTarget="Setting">时限与范围</span>
					</div>
				</div>
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
						
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
				
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
							
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});
				
					});
					// -->
					//]]>
				</script>
				
				<div id="Setting" class="tabContent">
					
					<div class="noticeBlock">
						<div class="operation">
							<a class="uiButton" href="<cfoutput>#buildURL('voteSetupWizardPreview', passArgs)#</cfoutput>"><i class="mrs img btnList"></i><span class="uiButtonText">预览</span></a>
						</div>
						<h3>调查问卷设置</h3>
						<p>
							<span class="img icon16x16 message"></span> 请根据实际需要, 再次确认在线调查问卷相关设置
						</p>
					</div>
					
					<form id="formUpdate" onSubmit="javascript:return processVerfiyForm('formUpdate');" class="formWrapper" method="post" action="<cfoutput>#buildURL('voteUpdateDo')#</cfoutput>">
						
						<input type="hidden" name="QueID" value="<cfoutput>#rs_quesEntity.qsn_id#</cfoutput>" />
						
						<div class="label">
							<b>标题</b>
							<input name="Title" id="Title" verification="required" type="text" class="typeText" maxlength="180" value="<cfoutput>#stringAdvice.HTMLFormEncode( rs_quesEntity.title )#</cfoutput>" />
						</div>
						
						<div class="label">
							<b>问卷调查说明</b>
							<textarea name="Describe" id="Describe" verification="required"><cfoutput>#stringAdvice.HTMLFormEncode( rs_quesEntity.describe )#</cfoutput></textarea>
						</div>
						
						<div class="label">
							<b>起止时间</b>
							<input name="DateStart" id="DateStart" type="text" class="typeDate" verification="date" maxlength="10" value="<cfoutput>#dateTimeAdvice.formatDateString( rs_quesEntity.date_start, 'YYYY-MM-DD')#</cfoutput>" /><span id="startTrigger" class="btnCalendar"></span>
							&nbsp;&nbsp;
							至
							&nbsp;&nbsp;
							<input name="DateEnd" id="DateEnd" type="text" class="typeDate" verification="date" maxlength="10" value="<cfoutput>#dateTimeAdvice.formatDateString( rs_quesEntity.date_end, 'YYYY-MM-DD')#</cfoutput>" /><span id="endTrigger" class="btnCalendar"></span>
							<p class="notice">该起止时间用于设置在线调查问卷的有效填写时间, 默认从建立后的第二天开始, 有效时间为 14 天. 若该时间设置不符合您的要求, 请自行更正.</p>
						</div>
						
						<hr/>
						
						<div class="label">
							<b>投票范围</b>
							
							<input name="FullGrade" id="FullGrade" type="checkbox" class="typeCheckbox" value="1" <cfif rs_quesEntity.grade_allowed eq "ALL">checked="checked"</cfif> /> 所有年级
							&nbsp;&nbsp;&nbsp;&nbsp;
							<input name="FullInstitute" id="FullInstitute" type="checkbox" class="typeCheckbox" value="1" <cfif rs_quesEntity.institute_allowed eq "ALL">checked="checked"</cfif> /> 所有学院
							&nbsp;&nbsp;&nbsp;&nbsp;
							<input name="FullGender" id="FullGender" type="checkbox" class="typeCheckbox" value="1" <cfif rs_quesEntity.gender_allowed eq "ALL">checked="checked"</cfif> /> 不限性别
							&nbsp;&nbsp;&nbsp;&nbsp;
							<input name="SpecialStudent" id="SpecialStudent" type="checkbox" class="typeCheckbox" value="1" <cfif rs_quesEntity.gender_allowed eq "NOP" and rs_quesEntity.institute_allowed eq "NOP" and rs_quesEntity.gender_allowed eq "NOP">checked="checked"</cfif> /> 特定学生
							
							<div id="notFullGrade" class="secondRow <cfif rs_quesEntity.grade_allowed eq "ALL" or rs_quesEntity.grade_allowed eq "NOP">hidden_elem</cfif> mtm">
								指定年级
								<cfset row = 0 />
                                <cfloop query="rs_grade">
									&nbsp;&nbsp;
									<input name="targetGrade" type="checkbox" class="typeCheckbox" value="<cfoutput>#rs_grade.grade#</cfoutput>" <cfif listFind( rs_quesEntity.grade_allowed, rs_grade.grade, "," )>checked="checked"</cfif> /> <cfoutput>#rs_grade.grade#</cfoutput>级 &nbsp;&nbsp;
								</cfloop>
							</div>

							<div id="notFullInstitute" class="secondRow <cfif rs_quesEntity.institute_allowed eq "ALL" or rs_quesEntity.institute_allowed eq "NOP">hidden_elem</cfif> mtm">
								指定学院
								<table>
									<tr>
										<cfset row = 0 />
										<cfset cellPerRow = 8 />
                                        <cfloop query="rs_institute">
											<cfset row++ />
												<td>
													<input name="targetInstitute" type="checkbox" class="typeCheckbox" value="<cfoutput>#rs_institute.institute_id#</cfoutput>" <cfif listFind( rs_quesEntity.institute_allowed, rs_institute.institute_id, "," )>checked="checked"</cfif> />
													<cfoutput>#rs_institute.institute_short#</cfoutput>
												</td>
											<cfif row mod cellPerRow eq 0>
									</tr>
									<tr>
											</cfif>
										</cfloop>
										<cfif row eq rs_institute.recordCount and rs_institute.recordCount mod cellPerRow>
											<cfloop from="1" to="#cellPerRow-rs_institute.recordCount mod cellPerRow#" index="i">
												<td><!-- <cfoutput>holder<cfoutput>#i#</cfoutput> --></cfoutput></td>
											</cfloop>
										</cfif>
									</tr>
								</table>
							</div>

							<div id="notFullGender" class="secondRow <cfif rs_quesEntity.gender_allowed eq "ALL" or rs_quesEntity.gender_allowed eq "NOP">hidden_elem</cfif> mtm">
								指定性别
								<input name="targetGender" type="checkbox" class="typeCheckbox" value="1" <cfif listFind( rs_quesEntity.gender_allowed, 1, "," )>checked="checked"</cfif> /> 男生
								<input name="targetGender" type="checkbox" class="typeCheckbox" value="2" <cfif listFind( rs_quesEntity.gender_allowed, 2, "," )>checked="checked"</cfif> /> 女生
							</div>

							<div id="toSpecialStudent" class="<cfif not ( rs_quesEntity.gender_allowed eq "NOP" and rs_quesEntity.institute_allowed eq "NOP" and rs_quesEntity.gender_allowed eq "NOP" )>hidden_elem</cfif> mtm">
								<textarea name="StudentIDs" id="StudentIDs" verification="required"><cfif rs_studentIds.recordCount><cfoutput>#arrayToList(rs_studentIds["stu_id"], ",")#</cfoutput><cfelse>NONE</cfif></textarea>
								<p class="notice">请在这里填写要指定参与投票学生的学号, 多个学号使用 , 或 换行 进行分割</p>
							</div>

						</div>
						
						<hr/>
						
						<div class="lable">
							<input class="button" type="submit" value="更新" />
						</div>
						
					</form>
					
					<script language="javascript" type="text/javascript">
						//<![CDATA[
						<!--
						$(document).ready(function() {
							
							$("#DateStart").mask("9999-99-99");
							$("#DateEnd").mask("9999-99-99");
							
							Calendar.setup({
									trigger    : "startTrigger",
									inputField : "DateStart",
									animation  : false
									});
								
							Calendar.setup({
									trigger    : "endTrigger",
									inputField : "DateEnd",
									animation  : false
									});
									
							$("#FullGrade").change(function(){
								
								var checked = $(this).prop("checked");
									
								if ( checked ) {
									$("#notFullGrade").addClass("hidden_elem");
									$("#notFullGrade :checkbox[name='targetGrade']").attr("checked","checked");
								}
								else {
									$("#notFullGrade").removeClass("hidden_elem");
									$("#notFullGrade :checkbox[name='targetGrade']").removeAttr("checked");
								}
								
							});
							
							$("#FullInstitute").change(function(){
								
								var checked = $(this).prop("checked");
									
								if ( checked ) {
									$("#notFullInstitute").addClass("hidden_elem");
									$("#notFullInstitute :checkbox[name='targetInstitute']").attr("checked","checked");
								}
								else {
									$("#notFullInstitute").removeClass("hidden_elem");
									$("#notFullInstitute :checkbox[name='targetInstitute']").removeAttr("checked");
								}
							});
							
							$("#FullGender").change(function(){
								
								var checked = $(this).prop("checked");
									
								if ( checked ) {
									$("#notFullGender").addClass("hidden_elem");
									$("#notFullGender :checkbox[name='targetGender']").attr("checked","checked");
								}
								else {
									$("#notFullGender").removeClass("hidden_elem");
									$("#notFullGender :checkbox[name='targetGender']").removeAttr("checked");
								}
							});
							
							
							$("#SpecialStudent").change(function(){
								
								var checked = $(this).prop("checked");
								
								if ( checked ) {
									
									$("#toSpecialStudent").removeClass("hidden_elem");
									$("#toSpecialStudent textarea").val("<cfif rs_studentIds.recordCount><cfoutput>#arrayToList(rs_studentIds["stu_id"], ',')#</cfoutput><cfelse>NONE</cfif>");
									
									var gradeChecked = $("#FullGrade").prop("checked");
									var instituteChecked = $("#FullInstitute").prop("checked");
									var genderChecked = $("#FullGender").prop("checked");

									if ( !gradeChecked ) {
										$("#notFullGrade").addClass("hidden_elem");
									}
									if ( !instituteChecked ) {
										$("#notFullInstitute").addClass("hidden_elem");
									}
									if ( !genderChecked ) {
										$("#notFullGender").addClass("hidden_elem");
									}
									
								}
								else {
									
									$("#toSpecialStudent").addClass("hidden_elem");
									$("#toSpecialStudent textarea").val("NONE");
									
									var gradeChecked = $("#FullGrade").prop("checked");
									var instituteChecked = $("#FullInstitute").prop("checked");
									var genderChecked = $("#FullGender").prop("checked");

									if ( !gradeChecked ) {
										$("#notFullGrade").removeClass("hidden_elem");
									}
									if ( !instituteChecked ) {
										$("#notFullInstitute").removeClass("hidden_elem");
									}
									if ( !genderChecked ) {
										$("#notFullGender").removeClass("hidden_elem");
									}
									
								}
								
							});

						});
						// -->
						//]]>
					</script>
					
				</div>
				
			</div>
		</li>
	</ul>
</div>